layui.use(['layer','table','jquery','form'],function(){
    let layer = layui.layer,
        table = layui.table,
        $ = layui.jquery,
        form = layui.form;

    //加载数据表格
    let tabInstance = table.render({
        elem: '#handleService',
        url: '/service-user-allot/handleService', //数据接口
        page: true, //开启分页
        limit:5, //每页显示的条数，默认10
        limits:[5,10,15,20,], //每页显示条数选择框数据
        request:{
            pageName: 'current',
            limitName: 'size'
        },
        cols: [[ //表头
            {field: 'serviceId', title: '编号', width:80, sort: true, fixed: 'left'},
            {field: 'customerName', title: '客户名称'},
            {field: 'outline', title: '概要'},
            {field: 'serviceType', title: '服务类型'},
            {field: 'creationName', title: '创建人'},
            {field: 'creationTime', title: '创建时间'},
            {field: 'serviceReq', title: '服务请求'},
            {field: 'userName', title: '分配给'},
            {field: 'status', title: '状态'},
            {title: '操作', width: 100,fixed:'right',toolbar:"#handleTool"}
        ]]
    });

    //搜索监听启用
    form.on('submit(search)',function(data){
        tabInstance.reload({
            where :data.field
        });
        return false;
    });

    //工具栏操作
    table.on('tool(handleService)',function(obj){
        switch (obj.event){
            case 'handle_btn':
                //分配
                let s =layer.open({
                    title:"服务处理",
                    type:2,
                    content:"views/service_management/handle.jsp",
                    area:['50%','70%'],
                    offset:'t',
                    skin:"layui-layer-molv",
                    btn:['确定','取消'],
                    //弹出层成功后执行的回调函数
                    success: function(layero, index){
                        let body = layer.getChildFrame("body",index);
                        body.find(".num").val(obj.data.serviceId);
                        body.find(".customerName").val(obj.data.customerName);
                        body.find(".outline").val(obj.data.outline);
                        body.find(".serviceType").val(obj.data.serviceType);
                        body.find(".creationName").val(obj.data.creationName);
                        body.find(".creationTime").val(obj.data.creationTime);
                        body.find(".serviceReq").val(obj.data.serviceReq);
                        body.find(".userName").val(obj.data.userName);
                        body.find(".status").val(obj.data.status);
                        body.find(".allotTime").val(obj.data.allotTime);
                    },
                    yes: function(index, layero){
                        let body = layer.getChildFrame("body",index);
                        let data = {};
                        body.find("#handleForm").serializeArray().forEach(function(item){
                            data[item.name] = item.value;
                        });
                        $.post('/service-user-allot/setHandleService',data,function(result){
                            layer.msg(result.msg);
                            setTimeout(function(){
                                layer.close(index);
                                parent.location.reload();
                            },500);

                        });
                    }
                });

                break;
        }
    });

});

